package RMIBank;

import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.util.*;

public class ConcreteBank extends UnicastRemoteObject implements Bank {

    private ArrayList<Account> accounts = new ArrayList<Account>();

    public ConcreteBank() throws RemoteException {
    }

    public Account getAccount(String name) throws RemoteException {
        for (Account a : accounts) {
            if (a.getName().equals(name)) {
                return a;
            }
        }

        //after looping the accountArray we knew that no account with the given name exists
        Account account = new ConcreteAccount(name);
        accounts.add(account);
        return account;
    }
}
